<?php
echo '<script>';

echo 'var noteMessageArr = new Array();';

foreach($allNotificationsTypes as $n)
{
	echo 'noteMessageArr.push("'.$n->getNotificationMessage().'");';
}

echo '</script>';
?>

<script>

function sendPromo()
{
	document.getElementById("notificationAction").value="send";
	document.notificationForm.submit();
}

function saveTemplate()
{
	document.notificationForm.submit();
}

function editTemplate()
{
	if(document.getElementById("notificationAction").value!="edit")
	{
		document.getElementById("notification_temp").value=document.getElementById("note_message").value;
		document.getElementById("notificationAction").value="edit";
		document.getElementById("note_message").disabled=false;
		document.getElementById("note_edit").value="Cancel Edit";
		document.getElementById("note_save").disabled=false;
		document.getElementById("note_selected").disabled=true;
	}
	else
	{
		document.getElementById("note_message").value=document.getElementById("notification_temp").value;
		document.getElementById("notificationAction").value="";
		document.getElementById("note_message").disabled=true;
		document.getElementById("note_edit").value="Edit";
		document.getElementById("note_save").disabled=true;
		document.getElementById("note_selected").disabled=false;
	}
}

function selectedNotification()
{
	var noteSelection = document.getElementById("note_selected");
	var selectedNoteIndex = noteSelection.selectedIndex;
	
	//alert(selectedNoteIndex);
	//alert(noteMessageArr[0]);
	
	document.getElementById("notification_id").value=selectedNoteIndex+1;
	document.getElementById("note_message").value=noteMessageArr[selectedNoteIndex];
	document.getElementById("notification_selected").value=selectedNoteIndex;

}

</script>

<td> 

<!------------------------------------------------------------------------>
<form name="notificationForm" action="#" method="post">	
	
	<input type="hidden" id="notificationAction" name="notificationAction" value="">
	<input type="hidden" id="notification_id" name="notification_id" value="">
	<input type="hidden" id="notification_selected" name="notification_selected" value="0">
	<input type="hidden" id="notification_temp" name="notification_temp" value="0">
    <div class="round2Inventory">
	<table class="content">
	
	<tr><td>Notification</td><td><br><br></td></tr>
	
	<tr>
		<td class="notification_left_col">	
			Notification Type: (Automatic)
		</td>
		
		<td rowspan="3" class="notification_center_col" >
			<textarea id="note_message" name="note_message" rows="6" cols="46" disabled><?php if(isset($notificationSelected)){echo $allNotificationsTypes[$notificationSelected]->getNotificationMessage();}else{echo $allNotificationsTypes[0]->getNotificationMessage();} ?></textarea>
		</td>
		
		<td rowspan="3" class="notification_right_col">
			<input type="button" id="note_edit" name="note_edit" value="Edit" onclick="editTemplate()"><br>
			<input type="button" id="note_save" name="note_save" value="Save" onclick="saveTemplate()" disabled>
		</td>
	</tr>
	
	<tr>
		<td class="notification_left_col">
		<select id="note_selected" name="note_selected" onchange="selectedNotification()">
			<?php
			$indexCount=0;
				foreach($allNotificationsTypes as $n)
				{
					if($n->getNotificationType() != 'Promo')
					{
					
						if(isset($notificationSelected) && $indexCount==$notificationSelected)
						{
							echo '<option value="'.$n->getNotificationId().'" selected>'.$n->getNotificationType().'</option>';
						}
						else
						{
							echo '<option value="'.$n->getNotificationId().'">'.$n->getNotificationType().'</option>';
						}
					}
					$indexCount++;
				}
			?>
		</select>
		</td>
		
		
	</tr>
	
	<tr><td><br></td></tr>
	
	
	<tr><td colspan="2" ><hr></td></tr>
	
	<tr>
		<td class="notification_left_col">	
			Notification Type: (Manual)
		</td>
		
		<td rowspan="3" class="notification_center_col">
			Subject<span class="red">*</span>: <input type="text" name="subject" size="50">
			<textarea rows="6" cols="46" name="content"></textarea>
		</td>
		
		<td rowspan="3" class="notification_right_col">
			<input type="button" name="note_send" value="Send Notification" width="60px" onclick="sendPromo()"><br>
		</td>
	</tr>
	
	<tr>
		<td class="notification_left_col">
			<select>
	 			<option value="note_promo">Promotion</option>	  			
			</select>
		</td>
		
		
	</tr>
	
	<tr><td><br></td></tr>
	
	</table>
	</div>
</form>			
<!------------------------------------------------------------------------>
			
			</td>
		</tr>
